<template>
	<view class="container">
		<view class="comment">
			<view class="comment-item" v-for="(item,index) in commentList" :key="index">
				<view class="comment-user">
					<view class="left">
						<u-image shape="circle" width="58" height="58" :src="item.headPhoto" mode="aspectFill"></u-image>
						<view class="user-name">{{item.nickName}}</view>
					</view>
					<view class="time">{{item.addTime}}</view>
				</view>
				<view class="rate">
					<u-rate active-color="#EABC05" :count="item.totalScore" v-model="item.totalScore"></u-rate>
				</view>
				<view class="photo" v-if="item.photoUrls != '' && item.photoUrls">
					<view v-for="(item1,index1) in item.photoUrls" :key="index1">
						<u-image :src="imgURL+item1" width="150rpx" height="150rpx" @click="imageView(index,index1)"></u-image>
					</view>
				</view>
				<view class="comment-content">{{item.context}}</view>
			</view>
		</view>
		<view class="empty" v-if="empty">
			<u-empty mode="list" text="暂无评价"></u-empty>
		</view>
		<u-loadmore v-else :status="status"></u-loadmore>
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				commentList: [],
				empty: false,
				imgURL: this.imageURL,
				status: 'loading'
			};
		},
		onLoad(options) {
			this.pageNo = 1
			this.goodsId = options.id
			this.getList(res => {
				if (res == '') {
					this.empty = true
					return
				}
				this.status = res.length < 10 ? 'nomore' : 'loadmore'
				this.commentList = res
			})
		},
		onReachBottom() {
			if (this.status == 'loading' || this.status == 'nomore') return
			this.status = 'loading'
			this.pageNo++
			this.getList(res => {
				if (res == '') {
					this.status = 'nomore'
					return
				}
				this.commentList = this.commentList.concat(res)
				this.status = 'loadmore'
			})
		},
		methods: {
			getList(callback) {
				this.$u.post('orderformcomment/goodsCommentList', {
					goodsId: this.goodsId,
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					let list = ''
					if (res) {
						if (res.list == '') {
							list = []
							return
						}
						res.list.forEach(item => {
							if (item.headPhoto) {
								if (item.headPhoto.indexOf("https") != 0) {
									item.headPhoto = this.imageURL + item.headPhoto
								}
							} else {
								item.headPhoto = this.appletImgUrl+'team-head-img.png'
							}
							if (item.photoUrls != '' && item.photoUrls) {
								item.photoUrls = item.photoUrls.split(',')
							}
						})
						list = res.list
					} else {
						list = []
					}
					callback(list)
				})
			},
			imageView(pindex, cindex) {
				let new_arr = []
				this.commentList[pindex].photoUrls.forEach(item => {
					new_arr.push(this.imageURL + item);
				})
				uni.previewImage({
					current: cindex,
					urls: new_arr
				})
			}
		}
	}
</script>

<style lang="scss">
	.empty {
		padding-top: 300rpx;
	}

	.container {
		padding: 30rpx;
		padding-top: 0;
	}

	.comment-item {
		padding: 20rpx 0;
		border-bottom: 1rpx solid #F7F7F7;

		.rate {
			padding-top: 20rpx;
		}

		.photo {
			display: flex;
			padding-top: 20rpx;

			>view {
				margin-left: 30rpx;

				&:first-child {
					margin-left: 0;
				}
			}
		}

		&:last-child {
			border-bottom: none;
		}

		.comment-user {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;
			}

			.time {
				font-size: 22rpx;

			}

			.user-name {
				margin-left: 20rpx;
				font-size: 28rpx;
			}
		}

		.comment-content {
			font-size: 28rpx;
			margin-top: 20rpx;
			color: #343434;
			line-height: 40rpx;
		}
	}
</style>
